package flc.ast.adapter;


import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyAlbumBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class SelCategoryAdapter extends StkProviderMultiAdapter<MyAlbumBean> {


    public SelCategoryAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new SelCategoryProvider());
    }

    private class SelCategoryProvider extends BaseItemProvider<MyAlbumBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_sel_category;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyAlbumBean bean) {
            if (baseViewHolder.getBindingAdapterPosition() == getItemCount() - 1) {
                baseViewHolder.setImageResource(R.id.ivSelCategoryItemIcon, R.drawable.atianjiafenl);
                baseViewHolder.setText(R.id.tvSelCategoryItemName, getContext().getString(R.string.add_category));
                baseViewHolder.setText(R.id.tvSelCategoryItemNum, "—— ——");
            } else {
                baseViewHolder.setImageResource(R.id.ivSelCategoryItemIcon, R.drawable.axiaoyingshi);
                baseViewHolder.setText(R.id.tvSelCategoryItemName, bean.getName());
                int num = bean.getListData().size();
                long size = 0;
                for (String listDatum : bean.getListData()) {
                    size += FileUtils.getFileLength(listDatum);
                }
                baseViewHolder.setText(R.id.tvSelCategoryItemNum, getContext().getString(R.string.video_num, num, ConvertUtils.byte2FitMemorySize(size, 1)));
            }
        }
    }

}
